# -*- coding: UTF-8 -*_
import requests
import threading

xczs = 16  # 这是线程数量，我放了128个差点把电脑卡死~~~
zh=1706010216
mm=233233
img_src='http://202.119.113.147/validateCodeAction.do?random=0.5'#获取验证码的链接
url='http://202.119.113.147/gradeLnAllAction.do?type=ln&oper=qbinfo&lnxndm'
url1='http://202.119.113.147/loginAction.do'#登录链接
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36'}#请求头
cookie={}
cookie['JSESSIONID']='cda05gqxW-erJhxF_tK9w'
data = {  # 需要post的数据
        "kcId[]": ['0601059_01','0601081_01','0601004_01'],
        "preActionType": '2',
        "actionType":'9',
    }

pd = False
def run_thread(n):
    i=n
    global pd
    global xz

    while True:
        response = requests.post('http://202.119.113.147/xkAction.do', data=data, headers=headers,cookies=cookie)  # 获取网页
        if (pd):
            return
        print(response.text)

        if '成功' in response.text:
            pd = True
            print('线程 ' + str(i) + ' 选课成功')
            # print(response.text)
            return

        if '不能选修' in response.text or 'Cannot find bean zhjw' in response.text:
            if (pd):
                continue
            print('选课失败,该课程不能选修~')
            pd = True
            return
        print('线程 ' + str(i) + ' 选课失败')



i=1
t = {}
while i <= xczs:
    t[i] = threading.Thread(target=run_thread, args=[i])
    print('创建线程 '+str(i))
    i += 1
i = 1
while i <= xczs:
    t[i].start()
    i += 1